package com.ouc.pampas;

import com.google.common.io.Resources;
import java.net.URL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class ClasspathFileLoader
  implements FileLoader
{
  private static final Logger log = LoggerFactory.getLogger(ClasspathFileLoader.class);
  
  public FileLoader.Resp load(String path)
  {
    path = Protocol.removeProtocol(path, Protocol.CLASSPATH);
    URL url = Resources.getResource(path);
    FileLoader.Resp resp = new FileLoader.Resp();
    try
    {
      resp.setContext(Resources.toByteArray(url));
      resp.setSign("UNSUPPORTED");
    }
    catch (Exception e)
    {
      log.error("error when load classpath file: {}", path, e);
      return FileLoader.Resp.NOT_FOUND;
    }
    return resp;
  }
  
  public FileLoader.Resp load(String path, String sign)
  {
    return FileLoader.Resp.NOT_MODIFIED;
  }
}
